﻿@model SAKS.ViewModels.UsersInRoleModel

@{
    ViewBag.Title = "角色成员管理" ;
}

<script type="text/javascript">
    $(function () {
        $(".RemoveLink").click(function () {
            var recordToDelete = $(this).attr("data-id");
            var role = $('#rolename').attr("rolename");
            if (recordToDelete != '') {
                $.post(
                    "/Admin/RemoveFromRole",
                    { "user": recordToDelete, "role": role },
                    function (data) {
                        if(data.Message == '移除成功')
                        {
                            $('#row-' + data.User).fadeOut('slow');
                        }
                        $('#update-message').text(data.Message);
                        
                    }
                );
            }
        });
    });
</script>

<h2>角色成员管理</h2>
<div id="rolename" rolename="@Model.Role">
    @Model.Role
</div>
<p>
    @Html.ActionLink("追加成员", "AddToRole", new { role = Model.Role })
</p>

    @if (ViewData["message"] != null)
    {    
        <div class="display-field">@ViewData["message"].ToString()</div> 
    }
    
    @if (Model.Users != null)
    {
        <table>
            <tr> 
                <th>
                    用户
                </th>
                <th></th>
            </tr>
        @foreach (var item in Model.Users)
        {
            <tr id="row-@item">
                <td><a href="#" class='username'>@item</a></td>
                <td>            
                    <a href="#" class="RemoveLink" data-id="@item" >移除</a>
                </td>    
            </tr>
        } 
        </table>
    }
<div id="update-message">
</div>
<p>
    @Html.ActionLink("返回角色列表", "AllRoles")
</p>

